package com.zbkj.admin.controller.platform;

import com.github.pagehelper.PageInfo;
import com.zbkj.dal.base.page.CommonPage;
import com.zbkj.dal.pojo.request.PageParamRequest;
import com.zbkj.dal.pojo.request.ba.ConcludeMaintainRequest;
import com.zbkj.dal.pojo.request.ba.MaintainQueryRequest;
import com.zbkj.dal.pojo.response.ba.MaintainDetailResponse;
import com.zbkj.dal.pojo.response.ba.MaintainResponse;
import com.zbkj.dal.base.result.CommonResult;
import com.zbkj.dal.common.utils.SecurityUtil;
import com.zbkj.dal.pojo.vo.LoginUserVo;
import com.zbkj.service.service.MaintainService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 维修保养
 * @author tianzhonghai
 * 2023/10/10 17:47
 */
@Slf4j
@RestController
@RequestMapping("api/admin/platform/maintain")
@Api(tags = "维修保养")
public class MaintainController {
    @Autowired
    private MaintainService maintainService;

    @ApiOperation(value = "分页获取评估鉴定信息")
    @RequestMapping(value = "/pageMaintain", method = RequestMethod.POST)
    public CommonResult<CommonPage<MaintainResponse>> queryMaintainPaged(@RequestBody MaintainQueryRequest maintainQueryRequest, PageParamRequest pageParamRequest) {
        if (CollectionUtils.isNotEmpty(maintainQueryRequest.getTimes())) {
            maintainQueryRequest.setBeginDate(maintainQueryRequest.getTimes().get(0));
            maintainQueryRequest.setEndDate(maintainQueryRequest.getTimes().get(1));
        }
        PageInfo<MaintainResponse> maintainPageInfo = maintainService.queryMaintainPaged(maintainQueryRequest, pageParamRequest);
        return CommonResult.success(CommonPage.restPage(maintainPageInfo));
    }

    @ApiOperation(value = "评估鉴定信息详情")
    @RequestMapping(value = "/detail/{id}", method = RequestMethod.GET)
    public CommonResult<MaintainDetailResponse> detail(@PathVariable("id")Integer id) {
        return CommonResult.success(maintainService.detail(id));
    }

    @ApiOperation(value = "评估鉴定")
    @RequestMapping(value = "/conclude", method = RequestMethod.POST)
    public CommonResult<Boolean> conclude(@RequestBody ConcludeMaintainRequest concludeMaintainRequest) {
        LoginUserVo loginUserVo = SecurityUtil.getLoginUserVo();
        concludeMaintainRequest.setOperatorId(loginUserVo.getUser().getId());
        return CommonResult.success(maintainService.conclude(concludeMaintainRequest));
    }
}
